﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using F_MODEL;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace F_DAL
{
   public class BookDetails_dal
    {
       string str = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
       /// <summary>
       /// 订单详情
       /// </summary>
       /// <param name="waybid"></param>
       /// <returns></returns>
       public List<UserAddrModel> getmails(string waybid)
       {
           using (SqlConnection conn = new SqlConnection(str))
           {
               using (SqlCommand cmd = conn.CreateCommand())
               {
                   conn.Open();
                   cmd.CommandText = @"select * from V_BookDetails where waybillId=@waybid";
                   cmd.Parameters.Add("@waybid", waybid);
                   List<UserAddrModel> list = new List<UserAddrModel>();
                   SqlDataReader reader = cmd.ExecuteReader();
                   while (reader.Read())
                   {
                       list.Add(new UserAddrModel()
                       {

                           mailId = reader["mailId"].ToString(),
                           mailStatus = Convert.ToInt32(reader["mailStatus"]),
                           origin = reader["origin"].ToString(),
                           name = reader["name"].ToString(),
                           cnTel = reader["cnTel"].ToString(),
                           flightInfo = reader["flightInfo"].ToString(),
                           destinationTime = Convert.ToDateTime(reader["destinationTime"]),
                           dweight = reader["dweight"].ToString(),
                           predictPrice = Convert.ToDecimal(reader["predictPrice"]),
                       });
                   }
                   return list;
               }
           }
       }
       /// <summary>
       /// 包裹明细
       /// </summary>
       /// <param name="mailid"></param>
       /// <returns></returns>
       public List<ParcelInfo>getparcel(string mailid)
       {
           using (SqlConnection conn = new SqlConnection(str))
           {
               using (SqlCommand cmd = conn.CreateCommand())
               {
                   conn.Open();
                   cmd.CommandText = @"select * from V_ParceDetailes where [mailId]=@mailid";
                   cmd.Parameters.Add("@mailid", mailid);

                   List<ParcelInfo> list = new List<ParcelInfo>();
                   SqlDataReader reader = cmd.ExecuteReader();
                   while (reader.Read())
                   {
                       ParcelInfo m = new ParcelInfo();
                       m.goodsType =Convert.ToInt32( reader["goodsType"]);
                       m.goodsName = reader["goodsName"].ToString();
                       m.goodsNum =Convert.ToInt32( reader["goodsNum"]);
                       m.goodsRemark = reader["goodsRemark"].ToString();
                       list.Add(m);
                   }
                   return list;
               }
           }
       }
       /// <summary>
       /// 确认交给飞人，修改状态
       /// </summary>
       /// <param name="waybillId"></param>
       /// <returns></returns>
       public int uptstate(string waybillId)
       {
           using (SqlConnection con=new SqlConnection(str))
           {
               using (SqlCommand cmd=con.CreateCommand())
               {
                   con.Open();
                   cmd.CommandText = @"update dbo.Waybill set waybillStatue=5 where waybillId=@waybillId";
                   cmd.Parameters.Add("@waybillId", waybillId);

                   int i = cmd.ExecuteNonQuery();
                   return i; 
               }
           }
       }
    }
}
